package com.ynet.eq.haiqing.module.datatran.service.impl;

import com.ynet.eq.haiqing.module.bean.MqttAddPersonsBaseReq;
import com.ynet.eq.haiqing.module.bean.MqttBaseReq;
import com.ynet.eq.haiqing.module.datatran.req.*;

import com.ynet.eq.haiqing.module.datatran.service.DataTranService;
import com.ynet.eq.haiqing.module.mqtt.MqttClientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static com.ynet.eq.haiqing.common.utils.GenerateMessageIdUtil.generateMessageId;

/**
 * @author 胡超雄
 * @date 2021/6/28 16:09
 * @desc
 */
@Slf4j
@Service
public class DataTranServiceImpl implements DataTranService {

    @Resource
    private MqttClientService mqttClientService;

    @Override
    public void addOrUpdateUser(AddOrUpdateUserReq req) {

        // 1 数据库相关的校验, TODO
        MqttBaseReq<AddOrUpdateUserReq> baseReq = new MqttBaseReq<>();
        baseReq.setId(req.getId());
        baseReq.setOperator("EditPerson");
        baseReq.setMessageId(generateMessageId());
        baseReq.setInfo(req);
        mqttClientService.doExecute(baseReq);

    }

    @Override
    public void queryCustomIds(QueryCustomIdsReq req) {
        // 1 数据库相关的校验, TODO
        MqttBaseReq<QueryCustomIdsReq> baseReq = new MqttBaseReq<>();
        baseReq.setId(req.getId());
        baseReq.setOperator("QueryPerson");
        baseReq.setMessageId(generateMessageId());
        baseReq.setInfo(req);
        mqttClientService.doExecute(baseReq);

    }

    @Override
    public void queryUser(QueryUserReq req) {
        //1 数据库先关校验
        MqttBaseReq<QueryUserReq> baseReq = new MqttBaseReq<>();
        baseReq.setId(req.getId());
        baseReq.setOperator("SearchPerson");
        baseReq.setMessageId(generateMessageId());
        baseReq.setInfo(req);
        mqttClientService.doExecute(baseReq);


    }

    @Override
    public void queryUserList(QueryUserListReq req) {
        MqttBaseReq<QueryUserListReq> baseReq = new MqttBaseReq<>();
        baseReq.setId(req.getId());
        baseReq.setOperator("SearchPersonList");
        baseReq.setMessageId(generateMessageId());
        baseReq.setInfo(req);
        mqttClientService.doExecute(baseReq);

    }

    @Override
    public void deleteUser(DeleteUserReq req) {
        //1 数据库先关校验
        MqttBaseReq<DeleteUserReq> baseReq = new MqttBaseReq<>();
        baseReq.setId(req.getId());
        baseReq.setOperator("DelPerson");
        baseReq.setMessageId(generateMessageId());
        baseReq.setInfo(req);
        mqttClientService.doExecute(baseReq);

    }

    @Override
    public void addOrUpdateUsers(AddOrUpdateUsersReq req) {
        //  4.10 批量添加或修改人员(URI)
        MqttAddPersonsBaseReq baseReq =new MqttAddPersonsBaseReq();
        baseReq.setId(req.getId());
        baseReq.setOperator("EditPersonsNew");
        baseReq.setMessageId(generateMessageId());
        baseReq.setInfo(req);
        baseReq.setPersonNum(req.infoSize());
        mqttClientService.doExecute(baseReq);
    }

    @Override
    public void queryProgress(QueryCustomIdsReq req) {
        MqttBaseReq baseReq = new MqttBaseReq();
        baseReq.setId(req.getId());
        baseReq.setOperator("QueryProgress");
        baseReq.setMessageId(generateMessageId());
        baseReq.setInfo(req);
        mqttClientService.doExecute(baseReq);
    }


}
